import request from '@/utils/request'

export function checkValidateCode() {
  return request({
    url: `${process.env.VUE_APP_MODULE_ADMIN_API}/public/client_code/check`,
    method: 'get',
    params: {
      'client_id': 'piece-vue'
    }
  })
}

export function getSocialData() {
  return request({
    url: `${process.env.VUE_APP_MODULE_ADMIN_API}/oauth/social/list`,
    method: 'get'
  })
}

export function getSocialLink(type, param) {
  return request({
    url: `${process.env.VUE_APP_MODULE_ADMIN_API}/oauth/social/redirect/${type}`,
    method: 'get',
    params: param
  })
}

export function getSocialBind(id) {
  return request({
    url: `${process.env.VUE_APP_MODULE_ADMIN_API}/oauth/social/user/${id}`,
    method: 'get'
  })
}

export function login(data) {
  return request({
    url: `${process.env.VUE_APP_MODULE_ADMIN_API}/authentication/doLogin`,
    method: 'post',
    headers: {
      'Authorization': 'Basic cGllY2UtdnVlOnBpZWNlLXZ1ZQ=='
    },
    data: data
  })
}

export function loginSocial(type, code, state) {
  return request({
    url: `${process.env.VUE_APP_MODULE_ADMIN_API}/oauth/social/quick_login/${type}`,
    method: 'post',
    headers: {
      'Authorization': 'Basic cGllY2UtdnVlOnBpZWNlLXZ1ZQ=='
    },
    data: {
      'code': code,
      'state': state
    }
  })
}

export function signup(data) {
  return request({
    url: `${process.env.VUE_APP_MODULE_ADMIN_API}/authentication/doRegister`,
    method: 'get',
    dataType: 'json',
    params: data
  })
}

export function bind(data) {
  return request({
    url: `${process.env.VUE_APP_MODULE_ADMIN_API}/oauth/social/bind_oauth/${data.type}`,
    method: 'get',
    params: data
  })
}

export function logout() {
  return request({
    url: `${process.env.VUE_APP_MODULE_ADMIN_API}/logout`,
    method: 'get'
  })
}

export function getInfo() {
  return request({
    url: `${process.env.VUE_APP_MODULE_ADMIN_API}/api/login/info`,
    method: 'get'
  })
}

export function userTable(query) {
  return request({
    url: `${process.env.VUE_APP_MODULE_ADMIN_API}/api/system/user/table`,
    method: 'post',
    data: query
  })
}

export function userLoad(query) {
  return request({
    url: `${process.env.VUE_APP_MODULE_ADMIN_API}/api/system/user/load`,
    method: 'get',
    params: query
  })
}

export function userSave(query) {
  return request({
    url: `${process.env.VUE_APP_MODULE_ADMIN_API}/api/system/user/save`,
    method: 'post',
    data: query
  })
}

export function userUpdate(query) {
  return request({
    url: `${process.env.VUE_APP_MODULE_ADMIN_API}/api/system/user/update`,
    method: 'post',
    data: query
  })
}

export function userExport(query) {
  return request({
    url: `${process.env.VUE_APP_MODULE_ADMIN_API}/api/system/user/export`,
    method: 'post',
    data: query
  })
}

export function userOnline(query) {
  return request({
    url: `${process.env.VUE_APP_MODULE_ADMIN_API}/api/system/user/online`,
    method: 'post',
    data: query
  })
}

export function userOffline(query) {
  return request({
    url: `${process.env.VUE_APP_MODULE_ADMIN_API}/api/system/user/offline`,
    method: 'post',
    data: query
  })
}

export function updateAvatar(query) {
  return request({
    url: `${process.env.VUE_APP_MODULE_ADMIN_API}/api/system/user/updateAvatar`,
    method: 'post',
    data: query
  })
}

export function resetPwd(id) {
  return request({
    url: `${process.env.VUE_APP_MODULE_ADMIN_API}/api/system/user/resetPwd/${id}`,
    method: 'post'
  })
}

export function updatePwd(id, query) {
  return request({
    url: `${process.env.VUE_APP_MODULE_ADMIN_API}/api/system/user/updatePwd/${id}`,
    method: 'post',
    data: query
  })
}

export function userDelete(query) {
  return request({
    url: `${process.env.VUE_APP_MODULE_ADMIN_API}/api/system/user/delete`,
    method: 'post',
    data: query
  })
}
